#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "labelscene.h"
#include "labelnamelistmodel.h"
#include "labellistmodel.h"
#include <QGraphicsView>
#include <QMainWindow>
#include <QAction>
#include <QButtonGroup>
#include <QStringListModel>
#include <QListView>
#include "polygonitem.h"
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    // loadFile(const QString& file = nullptr);
    void loadImage(const QString &filePath);
    void resizeEvent(QResizeEvent* event);
    void printSizes();
    void exportJsonPolygon(QGraphicsScene* scene, const QString& imagePath, int imageWidth, int imageHeight, const QString& savePath);
    void exportJsonRectangle(QGraphicsScene* scene, const QString& imagePath, int imageWidth, int imageHeight, const QString& savePath);
    void exportJsonClassification(QGraphicsScene* scene, const QString& imagePath, int imageWidth, int imageHeight, const QString& savePath);
private slots:
    void openFolder();
    void openImage();
    // void save();
    void saveAs();
    void zoomIn();
    void zoomOut();
    void normalSize();
    void modeChange();

    void polygonCreated(PolygonItem* polygonItem);
    void onItemRequestDelete(PolygonItem *item);
    void onItemRequestModify(PolygonItem *item);

    void openJson();

private:
    void recoverData(PolygonItem *item);
    void showTextDialog(PolygonItem *item, bool isNew);
    void createActions();
    void createMenus();
    void createToolBars();

    // updateActions();
    QStringListModel* flagModel;
    QListView* flagView;
    QString imagePath = "";
    bool isImageOpen = false;
    QStringListModel *imageListModel;
    QListView *imageListView;
    double scaleFactor = 1;
    LabelListModel *model;
    LabelNameListModel *labelNameListModel;
    QGraphicsView *graphicsView;
    LabelScene *scene;
    QGraphicsView *view;
    QPixmap pix;
    QButtonGroup *modeButtonGroup;
    // LabelListWidget *labelListWidget = new LabelListWidget;
    // LabelNameListWidget *labelNameListWidget = new LabelNameListWidget;


    QMenu *fileMenu;
    QMenu *editMenu;
    QAction *openAct;
    QAction *saveAsAct;
    QAction *exitAct;

    QAction *zoomInAct;
    QAction *zoomOutAct;
    QAction *normalSizeAct;

    QAction *createPolygonAct;
    QAction *createRectangleAct;
    QAction *editPolygonAct;

    QToolBar *fileToolBar;
    QToolBar *editToolBar;
    QToolBar *zoomToolBar;
    
    QAction *openImageAct;
    QAction *openJsonAct;
};
#endif // MAINWINDOW_H
